#include <stdio.h>
#include <arpa/inet.h>

typedef union 
{
    unsigned int value;
    unsigned char datas[4];
} Data;


int main(int argc, char const *argv[])
{
    char *ip = "192.168.2.136";
    Data ipdata; 

    // 将ip字符串转化为大端字节序的数值
    int ret = inet_pton(AF_INET, ip, &ipdata.value);
    printf("ret is %d,  ipNum is %d, LSB(%d),MSB(%d)\n", 
            ret, ipdata.value, ipdata.datas[0], ipdata.datas[3]);

    // 将大端Ip字节序的数值转化为字符串
    char ipstr[INET_ADDRSTRLEN] = "";
    inet_ntop(AF_INET, &ipdata.value, ipstr, INET_ADDRSTRLEN);
    printf("ret is %d, ip is %s\n", ret, ipstr);

    return 0;
}

